﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using wms_wpf.Apiservice;
using wms_wpf.InPut;

namespace wms_wpf.DialogViewModel
{
   public class Dialog3ViewModel : BindableBase, IDialogAware
    {


        private readonly IBaseService baseService;
        public DelegateCommand UpdateBoxCommand { get; set; }


        public string Title { get; set; } = "更新料盒";
        public event Action<IDialogResult> RequestClose;
    

        public Dialog3ViewModel(IBaseService baseService)
        {
            this.baseService = baseService;
            UpdateBoxCommand = new DelegateCommand(UpdateBox);
        }

        private string boxGridQuantity;
        public string BoxGridQuantity
        {
            get { return boxGridQuantity; }
            set { boxGridQuantity = value;RaisePropertyChanged(); }
        }

        public string BoxCode;

        public bool CanCloseDialog()
        {
            return true;
        }
        public void OnDialogClosed()
        {

        }
        public void OnDialogOpened(IDialogParameters parameters)
        {
            if (parameters.Count > 0)
            {
                BoxCode = parameters.GetValue<object>("1").ToString(); // 根据你的数据类型替换 'int'
            }
        
        }
        private async void UpdateBox()
        {
       

                InPut_BaseService2 inPut_BaseService2 = new InPut_BaseService2();
                inPut_BaseService2.BoxGridQuantity = BoxGridQuantity;
                inPut_BaseService2.BoxCode = BoxCode;   
                bool res = await baseService.Update_Box(inPut_BaseService2);
           
            if (res)
            {
                RequestClose?.Invoke(null);
            }



        }
    }
}
